<?php

namespace App\Repository\Order;

use App\Models\Order\OrderProductModel as model;
use Illuminate\Support\Facades\Cache;
use App\Repository\RoleRepository;
use Illuminate\Support\Facades\DB;
use App\Repository\BaseRepository;
use App\Repository\Order\OrderInfoRepository;

class OrderProductRepository extends  BaseRepository
{
  public function __construct()
  {
    $this->model = new model();
    $this->modelInfo = new OrderInfoRepository();
    parent::__construct();
  }
  //添加 订单插入
  // 1: 订单提交
  // 2: 数据验证判断
  // 3: 商品关联的产品判断
  public function add($data)
  {
    //必填 字段
    $mustField = [
      'idcard',
      'username'
    ];
    $optionalFields = $this->model->getTableField();
    $msgField = [
      'idcard' => '用户身份证证号不能为空',
      'username' => '用户身份证姓名不能为空',
    ];
    $insertData  = $this->getRealData($data, $mustField, $optionalFields, $msgField);
    if (!empty($insertData) && is_string($insertData)) {
      //返回错误参数
      return $this->returnMsg(
        2,
        $insertData
      );
    }
    $res = $this->model->insert($insertData);
    if ($res) {
      return $this->returnMsg(200, '上传成功');
    }
    return $this->returnMsg(1, '上传失败');
  }
  public function getOne($where, $field = ['*'])
  {
    return $this->model->where($where)->select($field)->first();
  }
  public function getCount($where)
  {
    return $this->model->where($where)->count();
  }
}
